<?php
include("../utility/connection.php");
include("../model/mSeminar.php");
session_start();

if($_SERVER["REQUEST_METHOD"] == "POST") {
    $ubah = trim(mysql_real_escape_string($_POST["hidUbah"]));
    if ($ubah == '1') {
        // ambil detil untuk ditampilakn di kolom perubahan
        $TopikId = trim(mysql_real_escape_string($_POST["hidIdTopik"]));
        $result = fnSelectSeminar($TopikId);
        $count = mysql_num_rows($result); // number of row
        $ubahSeminar = mysql_fetch_array($result);

        if ($count == 1) {
            $_SESSION['topikId']=$TopikId;
            $_SESSION['ubah']=$ubah;
            $_SESSION['ubahSeminar']=$ubahSeminar;
            header("location: ../ui/admin/seminarAdmin.php");
        } else {
            $_SESSION['topikId']=$TopikId;
            unset($_SESSION['ubah']);
            unset($_SESSION['ubahSeminar']);
            header("location: ../ui/admin/seminarAdmin.php");
        }
    } else if ($ubah == '2') {
        // hapus session2 yg gak diperlukan
        unset($_SESSION['ubah']);
        unset($_SESSION['ubahSeminar']);
        // simpan perubahan
        $TopikId = trim(mysql_real_escape_string($_POST["hidIdTopik"]));
        $Tema = trim(mysql_real_escape_string($_POST["txtTema"]));
        $DetilTema = trim(mysql_real_escape_string($_POST["txtUraian"]));
        $Tempat = trim(mysql_real_escape_string($_POST["txtTempat"]));
        $Tanggal = trim(mysql_real_escape_string($_POST["txtTanggal"]));
        $Waktu = trim(mysql_real_escape_string($_POST["txtWaktu"]));
        $TglAwalDaftar = trim(mysql_real_escape_string($_POST["txtTglAwalDaftar"]));
        $TglAkhirDaftar = trim(mysql_real_escape_string($_POST["txtTglAkhirDaftar"]));
        $Status = trim(mysql_real_escape_string($_POST["hidStsSeminar"]));
        fnUpdateSeminar($Tema,$DetilTema,$Tempat,$Tanggal,$Waktu,$Status,$TopikId,$TglAwalDaftar,$TglAkhirDaftar);
        // ambil detil lagi
        $result = fnSelectSeminar($TopikId);
        $count = mysql_num_rows($result); // number of row
        $seminarResult = mysql_fetch_array($result);

        if ($count == 1) {
            $_SESSION['topikId']=$TopikId;
            $_SESSION['seminarResult']=$seminarResult;
            header("location: ../ui/admin/seminarAdmin.php");
        } else {
            $_SESSION['topikId']=$TopikId;
            unset($_SESSION['seminarResult']);
            header("location: ../ui/admin/seminarAdmin.php");
        }
    }
}

?>
